package day03;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoCookie extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Date d=new Date();
		//下面的时间格式cookie中不能有空格
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
		String format = formatter.format(d);
//		req.getCookies();
		Cookie cookie=new Cookie("accessDate",format);
		cookie.setMaxAge(10);
		resp.addCookie(cookie);
	}
}
